import { computed } from 'vue'
import dayjs from 'dayjs'
import { getBeforeDayTimes, t } from '@/utils'

const format = 'YYYY-MM-DD HH:mm:ss'
export const useActivityDateTimes = () => {
	const today = dayjs().startOf('date').format(format)
	const seven = getBeforeDayTimes(7, format)
	const thirty = getBeforeDayTimes(30, format)
	const ninety = getBeforeDayTimes(90, format)

	const endTime = dayjs().endOf('day').format(format)
	// 今天结束之前的倒计时
	const todayEndTime = computed(() => Math.abs(dayjs().diff(dayjs().endOf('date'))))

	const dateSelects = [
		{
			id: 'all',
			name: 'activity.allDay',
			text: t('activity.allDay'),
			textT: 'activity.allDay',
			day: undefined,
			time: today
		},
		{
			id: 'today',
			name: 'activity.today',
			text: t('activity.today'),
			textT: 'activity.today',
			day: undefined,
			time: today
		},
		{
			id: 'seven',
			name: 'activity.days',
			text: 7 + ' ' + t('activity.days'),
			textT: 'activity.days',
			day: ['7'],
			time: seven
		},
		{
			id: 'thirty',
			name: 'activity.days',
			text: 30 + ' ' + t('activity.days'),
			textT: 'activity.days',
			day: ['30'],
			time: thirty
		},
		{
			id: 'ninety',
			name: 'activity.days',
			text: 90 + ' ' + t('activity.days'),
			textT: 'activity.days',
			day: ['90'],
			time: ninety
		}
	]

	return {
		today,
		seven,
		thirty,
		ninety,
		endTime,
		todayEndTime,
		dateSelects
	}
}
